﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.deepprocessing
{
    public class DeepprocessingHandler : IRequestHandler<DeepprocessingCommond, Rulst>
    {

        private readonly IbaseRpository<ProcessMess> _ProcessMess;

        public DeepprocessingHandler(IbaseRpository<ProcessMess> processMess)
        {
            _ProcessMess = processMess;
        }

        public async Task<Rulst> Handle(DeepprocessingCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };


            var list=_ProcessMess.Query().Where(x=>x.ProDuctionBasicid==request.ProDuctionBasicid).FirstOrDefault();

            if (list != null) {


                list.Processclass = request.Processclass;
                    list.ProcessPersonincharge=request.ProcessPersonincharge;

                _ProcessMess.update(list);
                query.Code = 1;
                query.MSG = "修改成功";
            }
            else
            {

                var query1 = new ProcessMess()
                {

                   Processclass = request.Processclass,
                   ProcessPersonincharge = request.ProcessPersonincharge,
                     ProDuctionBasicid = request.ProDuctionBasicid,
                     ProcessBossName="",
                     Processid=0,
                     Processlicence="",
                     ProcessLot="",
          
                    
                };
             var listt=   _ProcessMess.Add(query1);
                query.Code = 1;
                query.MSG = "添加成功";
            }


            return query;



        }
    }
}
